package com.wz.util;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.log4j.Logger;

public class MD5 {
	private static Logger log = Logger.getLogger(MD5.class);
	public static String encryptMD5(String strInput) {
        StringBuffer buf=null;
        try {
       	 MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(strInput.getBytes());
            byte b[] = md.digest();
             buf = new StringBuffer(b.length * 2);
            for(int i=0;i<b.length;i++) {
                if (((int)b[i] & 0xff) < 0x10) {
                    buf.append("0");
                }
               buf.append(Long.toHexString((int)b[i] & 0xff));
            }
        }catch(NoSuchAlgorithmException ex) {
             ex.printStackTrace();
        }
       return buf.toString().toUpperCase();
    }
	
	public static void main(String[] args) throws UnsupportedEncodingException {
		System.out.println(URLDecoder.decode("%25E6%2594%25AF%25E4%25BB%2598%25E6%2588%2590%25E5%258A%259F", "UTF-8"));
		//InterfaceNumber=1.0.0.0&InterfaceName=SZTF_WITHHOLDING&MerID=4000000002&MerAccount=400000000000002&OrderID=20141225170703600001718&CurId=0&PayValue=1&Datetime=20141225170626&BankID=8000013&Encode=UTF-8&MemberID=&Command=12&TranOrder=01000141225244777&TranStat=1001&TranInfo=%25E6%2594%25AF%25E4%25BB%2598%25E6%2588%2590%25E5%258A%259F&Attach=&Sign=9CF6A836387CD32D5AF17B8050EF88B3
//		SJSiUbnMKx5SlQRmSe0BDw==  Rr1VDKjuo3reuDZD
		System.out.println(MD5.encryptMD5("InterfaceNumber=1.0.0.0&InterfaceName=SZTF_WITHHOLDING&MerID=4000000002&MerAccount=400000000000002&OrderID=20141225170703600001718&CurId=0&PayValue=1&Datetime=20141225170626&BankID=8000013&Encode=UTF-8&MemberID=&Command=12&TranOrder=01000141225244777&TranStat=1001&TranInfo=%E6%94%AF%E4%BB%98%E6%88%90%E5%8A%9F&Attach=&Key=Rr1VDKjuo3reuDZD"));
	}
}
